<template>
  <page-container title="签约平台">
    <!-- 头部右侧操作按钮 -->
    <template #extra>
      <el-button type="primary" icon="Plus">
        添加签约平台
      </el-button>
      <el-button type="default" icon="Download" style="margin-left: 8px;">
        导出签约报告
      </el-button>
    </template>

    <div class="signing-platform">
      <!-- 1. 签约统计卡片（与码字日历统计卡片风格统一） -->
      <el-row :gutter="20" class="summary-cards" style="margin-bottom: 24px;">
        <el-col :span="6" :xs="12" :sm="8">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-item">
              <div class="stat-value">{{ summary.signedCount || 0 }}</div>
              <div class="stat-label">已签约平台</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6" :xs="12" :sm="8">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-item">
              <div class="stat-value">{{ summary.negotiatingCount || 0 }}</div>
              <div class="stat-label">洽谈中平台</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6" :xs="12" :sm="8">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-item">
              <div class="stat-value">{{ summary.unsignedCount || 0 }}</div>
              <div class="stat-label">未申请平台</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6" :xs="12" :sm="8">
          <el-card shadow="hover" class="stat-card">
            <div class="stat-item">
              <div class="stat-value">{{ summary.monthlyIncome || 0 }}元</div>
              <div class="stat-label">上月签约收入</div>
            </div>
          </el-card>
        </el-col>
      </el-row>

      <!-- 2. 签约平台列表 -->
      <el-card shadow="hover" class="platform-list-card">
        <template #header>
          <div class="list-header">
            <span class="list-title">平台签约详情</span>
            <el-input
              v-model="searchKey"
              placeholder="搜索平台名称"
              style="width: 240px;"
              prefix-icon="Search"
              size="small"
            />
          </div>
        </template>

        <!-- 列表内容 -->
        <div class="platform-list">
          <!-- 空状态（与码字日历空提示风格统一） -->
          <el-empty
            v-if="platforms.length === 0 && !loading"
            description="暂无签约平台数据，点击「添加签约平台」开始管理"
            class="empty-tip"
          />

          <!-- 平台列表网格 -->
          <el-row :gutter="24" v-else>
            <el-col :span="8" :xs="24" :sm="12" v-for="(platform, index) in platforms" :key="index">
              <div class="platform-card">
                <!-- 平台图标与状态 -->
                <div class="platform-header">
                  <div class="platform-icon" :style="{ backgroundColor: platform.color }">
                    <i :class="platform.icon" />
                  </div>
                  <el-tag
                    :type="
                      platform.status === '已签约' ? 'success' : 
                      platform.status === '洽谈中' ? 'warning' : 'info'
                    "
                    size="small"
                  >
                    {{ platform.status }}
                  </el-tag>
                </div>

                <!-- 平台信息 -->
                <div class="platform-info">
                  <h3 class="platform-name">{{ platform.name }}</h3>
                  <p class="platform-type">主营类型：{{ platform.type }}</p>
                  <p class="platform-signDate">签约时间：{{ platform.signDate || '未签约' }}</p>
                  <p class="platform-income">月均收入：{{ platform.monthlyIncome || 0 }}元</p>
                </div>

                <!-- 操作按钮 -->
                <div class="platform-actions">
                  <el-button type="text" size="small" @click="handleViewDetail(platform)">
                    查看详情
                  </el-button>
                  <el-button type="text" size="small" @click="handleEdit(platform)" style="color: #409eff;">
                    编辑
                  </el-button>
                  <el-button type="text" size="small" @click="handleTerminate(platform)" style="color: #f56c6c;">
                    解约
                  </el-button>
                </div>
              </div>
            </el-col>
          </el-row>

          <!-- 分页（模拟） -->
          <div class="pagination" style="margin-top: 20px; text-align: right;">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[6, 12, 24]"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="platforms.length"
            />
          </div>
        </div>
      </el-card>
    </div>
  </page-container>
</template>

<script setup>
import { ref } from 'vue';
import { ElMessage } from 'element-plus';
import PageContainer from '@/components/PageContainer.vue';

// 模拟数据：签约统计
const summary = ref({
  signedCount: 2,
  negotiatingCount: 1,
  unsignedCount: 3,
  monthlyIncome: 8500
});

// 模拟数据：签约平台列表
const platforms = ref([
  {
    id: 1,
    name: '起点中文网',
    type: '男频小说（玄幻/都市）',
    status: '已签约',
    signDate: '2025-03-15',
    monthlyIncome: 5200,
    color: '#409eff',
    icon: 'el-icon-document'
  },
  {
    id: 2,
    name: '晋江文学城',
    type: '女频小说（古言/现言）',
    status: '已签约',
    signDate: '2025-05-22',
    monthlyIncome: 3300,
    color: '#67c23a',
    icon: 'el-icon-s-shop'
  },
  {
    id: 3,
    name: '番茄小说',
    type: '全品类（短篇/爽文）',
    status: '洽谈中',
    signDate: '',
    monthlyIncome: 0,
    color: '#e6a23c',
    icon: 'el-icon-notebook-2'
  },
  {
    id: 4,
    name: '纵横中文网',
    type: '男频小说（武侠/历史）',
    status: '未申请',
    signDate: '',
    monthlyIncome: 0,
    color: '#909399',
    icon: 'el-icon-book'
  },
  {
    id: 5,
    name: '潇湘书院',
    type: '女频小说（仙侠/甜宠）',
    status: '未申请',
    signDate: '',
    monthlyIncome: 0,
    color: '#909399',
    icon: 'el-icon-girl'
  },
  {
    id: 6,
    name: '飞卢小说网',
    type: '男频小说（同人/脑洞）',
    status: '未申请',
    signDate: '',
    monthlyIncome: 0,
    color: '#909399',
    icon: 'el-icon-boy'
  }
]);

// 分页与搜索
const currentPage = ref(1);
const pageSize = ref(6);
const searchKey = ref('');
const loading = ref(false);

// 模拟操作方法
const handleViewDetail = (platform) => {
  ElMessage.info(`查看 ${platform.name} 详情`);
};
const handleEdit = (platform) => {
  ElMessage.info(`编辑 ${platform.name}`);
};
const handleTerminate = (platform) => {
  ElMessage.info(`解约 ${platform.name}`);
};
const handleSizeChange = (val) => {
  pageSize.value = val;
};
const handleCurrentChange = (val) => {
  currentPage.value = val;
};
</script>

<style lang="scss" scoped>
.signing-platform {
  // 复用码字日历统计卡片样式
  .summary-cards {
    .stat-card {
      .stat-item {
        text-align: center;
        padding: 20px 0;
        .stat-value {
          font-size: 24px;
          font-weight: bold;
          color: #409eff;
          margin-bottom: 8px;
        }
        .stat-label {
          font-size: 14px;
          color: #909399;
        }
      }
    }
  }

  // 列表头部
  .list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .list-title {
      font-size: 16px;
      font-weight: 500;
      color: #303133;
    }
  }

  // 平台卡片样式
  .platform-card {
    border: 1px solid #e4e7ed;
    border-radius: 8px;
    padding: 16px;
    transition: all 0.3s;
    background-color: #fff;
    &:hover {
      border-color: #409eff;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.08);
    }

    // 卡片头部（图标+状态）
    .platform-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 12px;
      .platform-icon {
        width: 36px;
        height: 36px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: #fff;
        i {
          font-size: 18px;
        }
      }
    }

    // 卡片信息
    .platform-info {
      .platform-name {
        font-size: 16px;
        font-weight: 500;
        color: #303133;
        margin-bottom: 8px;
      }
      .platform-type,
      .platform-signDate,
      .platform-income {
        font-size: 12px;
        color: #909399;
        margin-bottom: 4px;
      }
    }

    // 操作按钮
    .platform-actions {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      margin-top: 16px;
      button {
        font-size: 12px;
        margin-left: 8px;
      }
    }
  }

  // 空状态
  .empty-tip {
    padding: 40px 0;
  }
}
</style>